package com.loyi.cloud.hbsystem.cqi.utils;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.commons.lang3.time.StopWatch;
import org.apache.commons.math3.stat.StatUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import com.loyi.cloud.hbmis.api.IQueryService;

/**
 * 综合质量指数统计类
 * 
 * @author Administrator
 * 
 */
public class CQITotalService implements DisposableBean {

	private Logger log = LoggerFactory.getLogger(this.getClass());

	private IQueryService queryService;

	private boolean isRunning = false;

	private int finish = 0;

	private int total;

	private long starttime;

	private String single = "SINGLE";

	public int getTotal() {
		return total;
	}

	public long getStarttime() {
		return starttime;
	}

	public boolean isRunning() {
		return isRunning;
	}

	public int getFinish() {
		return finish;
	}

	public void setQueryService(IQueryService queryService) {
		this.queryService = queryService;
	}

	public IQueryService getQueryService() {
		return queryService;
	}

	/**
	 * 要统计的污染物，由外部注入
	 */
	private List<Map<String, Object>> polls = new ArrayList<Map<String, Object>>();

	public void setPolls(List<Map<String, Object>> polls) {
		this.polls = polls;
	}

	public List<Map<String, Object>> getPolls() {
		return polls;
	}

	/**
	 * 判断指定日期是否已经汇总过
	 * 
	 * @param datatime
	 * @param type
	 *            汇总类型，0=小时报，1=日报，2=周报，3=月报，4=季报，5=半年报，6=年报
	 * @return
	 */
	public boolean isTotal(Date datatime, int type) {
		List<Map<String, Object>> result;
		String sql = String.format("SELECT count(cqi) AS count FROM t_bas_cqi_total WHERE datatime='%s' AND type='%s'",
				DateFormatUtils.format(datatime, "yyyy-MM-dd HH:mm:ss"), type);
		result = this.queryService.query(sql);
		if (result.size() > 0 && Integer.parseInt(result.get(0).get("count").toString()) > 0) {
			return true;
		}
		return false;
	}

	/**
	 * 
	 * @param datatime
	 * @param type
	 */
	public void execute(Date datatime, int type) {
		Date starttime, endtime;
		int quarter, month, week;
		long s;
		StopWatch topWatch, pointerWatch;

		ThreadPoolTaskExecutor taskExecutor;
		List<Map<String, Object>> result, result1;
		String sql, dateFormat = "yyyy-MM-dd HH:mm:ss";
		Calendar calendar;
		datatime = DateUtils.setMilliseconds(datatime, 0);
		datatime = DateUtils.setMinutes(datatime, 0);
		datatime = DateUtils.setSeconds(datatime, 0);
		calendar = Calendar.getInstance();
		log.info("开始统计综合质量指数" + DateFormatUtils.format(datatime, dateFormat));

		while (true) {
			synchronized (single) {
				if (!this.isRunning) {
					this.isRunning = true;
					break;
				}
			}
			log.warn("有汇总任务正在进行，等待执行中....");
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		finish = 0;
		s = System.currentTimeMillis();
		switch (type) {
		case 0:// 小时
			starttime = DateUtils.addHours(datatime, -1);
			// starttime = DateUtils.addMinutes(starttime, 1);
			endtime = DateUtils.addHours(datatime, 0);
			endtime = DateUtils.addMinutes(endtime, -1);
			log.info(String.format("[%s]时综合质量指数", DateFormatUtils.format(datatime, "yyyy-MM-dd HH")));
			log.info(String.format("%s 至 %s", DateFormatUtils.format(starttime, dateFormat),
					DateFormatUtils.format(endtime, dateFormat)));

			break;
		case 1:// 日
			datatime = DateUtils.setHours(datatime, 0);
			starttime = DateUtils.addHours(datatime, 0);

			endtime = DateUtils.addHours(datatime, 24);
			endtime = DateUtils.addMinutes(endtime, -1);
			log.info(String.format("[%s]日综合质量指数", DateFormatUtils.format(datatime, "yyyy-MM-dd")));
			log.info(String.format("%s 至 %s", DateFormatUtils.format(starttime, "yyyy-MM-dd HH:mm:ss"),
					DateFormatUtils.format(endtime, "yyyy-MM-dd HH:mm:ss")));

			break;
		case 2:// 周
			datatime = DateUtils.setHours(datatime, 0);
			calendar.setTime(datatime);
			week = calendar.get(Calendar.WEEK_OF_MONTH);
			calendar.set(Calendar.DAY_OF_WEEK, 1);
			datatime = calendar.getTime();
			starttime = datatime;
			endtime = DateUtils.addWeeks(datatime, 1);
			endtime = DateUtils.addMinutes(endtime, -1);
			log.info(String.format("[%s]月第%s周综合质量指数", DateFormatUtils.format(datatime, "yyyy-MM"), week));
			log.info(String.format("%s 至 %s", DateFormatUtils.format(starttime, "yyyy-MM-dd HH:mm:ss"),
					DateFormatUtils.format(endtime, "yyyy-MM-dd HH:mm:ss")));
			break;
		case 3:// 月
			datatime = DateUtils.setHours(datatime, 0);
			datatime = DateUtils.setDays(datatime, 1);
			starttime = datatime;
			// starttime = DateUtils.addMinutes(starttime, 1);
			endtime = DateUtils.addMonths(datatime, 1);
			endtime = DateUtils.addMinutes(endtime, -1);
			log.info(String.format("[%s]月综合质量指数", DateFormatUtils.format(datatime, "yyyy-MM")));
			log.info(String.format("%s 至 %s", DateFormatUtils.format(starttime, "yyyy-MM-dd HH:mm:ss"),
					DateFormatUtils.format(endtime, "yyyy-MM-dd HH:mm:ss")));
			break;
		case 4:// 季度
			datatime = DateUtils.setHours(datatime, 0);
			datatime = DateUtils.setDays(datatime, 1);
			calendar.setTime(datatime);
			month = calendar.get(Calendar.MONTH);
			quarter = (int) Math.floor(month / 3);
			calendar.set(Calendar.MONTH, (quarter * 3));
			datatime = calendar.getTime();
			starttime = datatime;
			// starttime = DateUtils.addMinutes(starttime, 1);
			endtime = DateUtils.addMonths(datatime, 3);
			endtime = DateUtils.addMinutes(endtime, -1);
			log.info(String.format("[%s]第%s季度综合质量指数", DateFormatUtils.format(datatime, "yyyy-MM"), quarter + 1));
			log.info(String.format("%s 至 %s", DateFormatUtils.format(starttime, "yyyy-MM-dd HH:mm:ss"),
					DateFormatUtils.format(endtime, "yyyy-MM-dd HH:mm:ss")));
			break;
		case 5:// 半年
			boolean isBeforeYear = false;
			datatime = DateUtils.setHours(datatime, 0);
			datatime = DateUtils.setDays(datatime, 1);

			if (DateUtils.toCalendar(datatime).get(Calendar.MONTH) > 5) {
				datatime = DateUtils.setMonths(datatime, 6);
				isBeforeYear = false;
			} else {
				datatime = DateUtils.setMonths(datatime, 0);
				isBeforeYear = true;// 上半年
			}
			starttime = datatime;
			// starttime = DateUtils.addMinutes(starttime, 1);
			endtime = DateUtils.addMonths(datatime, 6);

			endtime = DateUtils.addMinutes(endtime, -1);
			log.info(String.format("[%s]%s综合质量指数", DateFormatUtils.format(datatime, "yyyy"),
					isBeforeYear ? "上半年" : "下半年"));
			log.info(String.format("%s 至 %s", DateFormatUtils.format(starttime, "yyyy-MM-dd HH:mm:ss"),
					DateFormatUtils.format(endtime, "yyyy-MM-dd HH:mm:ss")));
			break;
		case 6:// 年度
			datatime = DateUtils.setHours(datatime, 0);
			datatime = DateUtils.setDays(datatime, 1);
			datatime = DateUtils.setMonths(datatime, 0);
			starttime = datatime;
			starttime = DateUtils.addMinutes(starttime, 1);
			endtime = DateUtils.addYears(datatime, 1);
			endtime = DateUtils.addMinutes(endtime, -1);
			log.info(String.format("[%s]年综合质量指数", DateFormatUtils.format(datatime, "yyyy")));
			log.info(String.format("%s 至 %s", DateFormatUtils.format(starttime, "yyyy-MM-dd HH:mm:ss"),
					DateFormatUtils.format(endtime, "yyyy-MM-dd HH:mm:ss")));
			break;
		default:
			return;
		}

		taskExecutor = new ThreadPoolTaskExecutor();
		taskExecutor.setCorePoolSize(10);
		taskExecutor.setQueueCapacity(1000);
		taskExecutor.setThreadNamePrefix("cqiTotal");
		taskExecutor.setThreadPriority(Thread.MAX_PRIORITY - 1);
		taskExecutor.initialize();
		taskExecutor.setWaitForTasksToCompleteOnShutdown(false);

		calendar.setTime(datatime);

		try {
			sql = "SELECT  * FROM t_bas_cqi_relation GROUP BY region";
			result = this.queryService.query(sql);

			log.debug("区域数=" + result.size());

			total = result.size();
			finish = 0;
			this.starttime = System.currentTimeMillis();

			for (Map<String, Object> region : result) {
				taskExecutor.execute(
						new CqiTotalThread(datatime, starttime, endtime, region.get("region").toString(), type));

			}
			while (this.finish < result.size()) {
				log.debug(String.format("完成进度：%s/%s", finish, result.size()));
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}

			}
			log.info(String.format("汇总数据完毕，共计用时：%s ms", System.currentTimeMillis() - s));
		} catch (Exception ex) {
			log.warn("汇总数据出现异常", ex);
		}

		taskExecutor.destroy();
		taskExecutor = null;
		synchronized (this.single) {
			isRunning = false;
		}

	}

	class CqiTotalThread implements Runnable {

		private Date datatime;
		private Date starttime;
		private Date endtime;
		private String region;
		private int type;

		public CqiTotalThread(Date datatime, Date starttime, Date endtime, String region, int type) {
			this.datatime = datatime;
			this.starttime = starttime;
			this.endtime = endtime;
			this.region = region;
			this.type = type;
		}

		public void run() {
			List<Map<String, Object>> result, result1;
			String sql, dateFormat = "yyyy-MM-dd HH:mm:ss";
			try {
				sql = String.format(
						"SELECT p.* from t_bas_pointer AS p LEFT JOIN t_bas_cqi_relation AS r ON r.ptid=p.ptid WHERE  r.region='%s'",
						region);
				result1 = queryService.query(sql);
				for (Map<String, Object> pointer : result1) {
					totalPointer(datatime, starttime, endtime, pointer.get("ptid").toString(), type);
				} // end pointer
				totalRegion(datatime, starttime, endtime, region, type);
			} catch (Exception ex) {
				log.warn("汇总失败", ex);
			}
			synchronized (single) {
				finish++;
				log.debug("已完成" + finish);
			}

		}
	}

	public void totalRegion(Date datatime, Date starttime, Date endtime, String region, int type) {
		int count, available, intCode, minCount, dayCount = 0, radix = 0;
		float high, low, value, icqi, cqi, maxicqi;
		List<Map<String, Object>> result, result1, result2;
		Map<String, Object> detail, keys, total;
		String sql, maxpoll, dateFormat = "yyyy-MM-dd HH:mm:ss", pollcode;
		Calendar calendar;
		// 删除历史记录
		keys = new HashMap<String, Object>();
		keys.put("datatime", DateFormatUtils.format(datatime, dateFormat));
		keys.put("targetid", region);
		keys.put("targettype", 1);
		keys.put("type", type);
		this.clear(keys);

		cqi = 0.0f;
		available = 1;
		maxpoll = "";
		maxicqi = 0.0f;
		icqi = 0.0f;

		// 统计有效天数
		if (type >= 2) {
			sql = String.format(
					"SELECT COUNT(cqi) AS count FROM t_bas_cqi_total  WHERE  type=1  AND datatime BETWEEN '%s' AND '%s' AND targettype=1 AND targetid='%s' AND available=1",
					DateFormatUtils.format(starttime, dateFormat), DateFormatUtils.format(endtime, dateFormat), region);
			log.debug(sql);
			result = this.queryService.query(sql);
			log.debug(result.toString());
			if (result.size() > 0 && result.get(0).get("count") != null) {
				dayCount = Integer.parseInt(result.get(0).get("count").toString());
				log.debug("有效天数为" + dayCount);
			}
		}

		for (Map<String, Object> poll : polls) {
			pollcode = poll.get("pollcode").toString();
			intCode = Integer.parseInt(pollcode, 16);
			if (poll.get("radix") != null) {
				radix = Integer.parseInt(poll.get("radix").toString());
			}
			// log.debug(String.format("污染物%s", poll.get("name")));
			sql = String.format(
					"SELECT d.value FROM t_bas_cqi_total_detail  AS d LEFT JOIN t_bas_cqi_total AS m ON m.datatime=d.datatime AND m.targettype=d.targettype AND m.targetid=d.targetid AND m.type=d.type WHERE  m.available=1 AND  d.datatime='%s' AND d.type=%s  AND d.targettype=0 AND d.targetid IN(SELECT ptid FROM t_bas_cqi_relation WHERE region='%s') AND d.pollcode='%s' AND d.value>%s AND d.value<%s  ORDER BY value",
					DateFormatUtils.format(datatime, dateFormat), type, region, pollcode, poll.get("minvalue"),
					poll.get("maxvalue"));
			log.debug("sql2:" + sql);
			result2 = this.queryService.query(sql);
			double[] values = getValues(result2, "value");
			high = value = low = 0.0f;
			count = values.length;
			icqi = 0;
			if (count > 0) {
				// 只要有1个以上有效站点
				value = (float) StatUtils.mean(values);
				high = (float) StatUtils.max(values);
				low = (float) StatUtils.min(values);
				if (radix > 0) {
					value = ((int) (value * radix)) / (float) radix;
					high = ((int) (high * radix)) / (float) radix;
					low = ((int) (low * radix)) / (float) radix;
				}
				icqi = CQIHelper.getCQI(poll.get("pollcode").toString(), value);

				cqi += icqi;
				if (icqi > maxicqi) {
					maxicqi = icqi;
					maxpoll = poll.get("name").toString();
				} else if (icqi == maxicqi) {
					maxpoll = String.format("%s,%s", maxpoll, poll.get("name"));
				}
			} else {
				available = 0;// 当前为不可用
			}

			detail = new HashMap<String, Object>();
			detail.putAll(poll);
			detail.putAll(keys);
			detail.put("icqi", icqi);
			detail.put("high", high);
			detail.put("count", count);
			detail.put("low", low);
			detail.put("value", value);
			this.saveDetail(detail);

		} // end polls
		total = new HashMap<String, Object>();
		total.putAll(keys);
		total.put("cqi", cqi);
		total.put("maxicqi", maxicqi);
		total.put("maxpoll", maxpoll);
		total.put("available", available);
		total.put("count", dayCount);
		this.saveTotal(total);
	}

	/**
	 * 
	 * @param datatime
	 * @param starttime
	 * @param endtime
	 * @param ptid
	 */
	public void totalPointer(Date datatime, Date starttime, Date endtime, String ptid, int type) {
		int count, available, intCode, minCount, dayCount = 0, radix = 0;
		float high, low, value, icqi, cqi, maxicqi;
		List<Map<String, Object>> result, result1, result2;
		Map<String, Object> detail, keys, total;
		String sql, maxpoll, dateFormat = "yyyy-MM-dd HH:mm:ss", pollcode;
		Calendar calendar;
		Date oldStarttime;

		oldStarttime = starttime;

		// 删除历史记录
		keys = new HashMap<String, Object>();
		keys.put("datatime", DateFormatUtils.format(datatime, dateFormat));
		keys.put("targetid", ptid);
		keys.put("targettype", 0);
		keys.put("type", type);
		this.clear(keys);

		cqi = 0.0f;
		available = 1;
		maxpoll = "";
		maxicqi = 0.0f;
		icqi = 0.0f;

		// 统计有效天数
		if (type >= 2) {
			sql = String.format(
					"SELECT COUNT(cqi) AS count FROM t_bas_cqi_total WHERE (datatime BETWEEN '%s' AND '%s') AND targetid='%s' AND targettype=%s AND  type=1 AND available=1",
					ptid, 0, DateFormatUtils.format(starttime, dateFormat),
					DateFormatUtils.format(endtime, dateFormat));
			result = this.queryService.query(sql);
			log.debug(sql);

			if (result.size() > 0 && result.get(0).get("count") != null) {
				dayCount = Integer.parseInt(result.get(0).get("count").toString());
			}
			log.debug("有效天数" + dayCount);
		}

		for (Map<String, Object> poll : polls) {
			pollcode = poll.get("pollcode").toString();
			intCode = Integer.parseInt(pollcode, 16);
			if (poll.get("radix") != null) {
				radix = Integer.parseInt(poll.get("radix").toString());
			}

			// log.info(String.format("污染物%s", poll.get("name")));
			if (type >= 2) {
				// 年、半年，季度、月、周
				sql = String.format(
						"SELECT m.datatime,d.value FROM  t_bas_cqi_total_detail AS d LEFT JOIN t_bas_cqi_total AS m ON m.datatime=d.datatime AND m.targettype=d.targettype AND m.targetid=d.targetid AND m.type=d.type WHERE m.available=1  AND  d.datatime BETWEEN '%s' AND '%s'  AND d.type=1 AND d.targettype=0 AND d.targetid='%s' AND  d.pollcode='%s' AND d.value BETWEEN %s  AND %s ",
						DateFormatUtils.format(starttime, dateFormat), DateFormatUtils.format(endtime, dateFormat),
						ptid, pollcode, poll.get("minvalue"), poll.get("maxvalue"));
			} else {
				// 日
				if ((intCode & 0x0FFF) == 0x0D71) {
					starttime = DateUtils.addHours(oldStarttime, 8);// 增加8小时逻辑
				} else {
					starttime = oldStarttime;	
				}
				sql = String.format(
						"SELECT ptid,pollcode,datatime,value FROM t_bas_data_hour AS r WHERE  (r.datatime BETWEEN %s AND %s)  AND  r.ptid='%s'  AND   r.pollcode='%s' AND (r.value BETWEEN %s AND %s)",
						starttime.getTime(), endtime.getTime(), ptid, pollcode, poll.get("minvalue"),
						poll.get("maxvalue"));
			}
			log.debug(sql);
			StopWatch w = new StopWatch();
			w.start();
			result2 = this.queryService.query(sql);
			w.stop();
			log.debug("查询用时：" + w.getTime());
			double[] values = getValues(result2, "value");
			high = value = low = 0.0f;
			count = values.length;
			icqi = 0.0f;
			if (count >= getMinCount(datatime, type, intCode)) {
				// 判断是否为有效长度，不通污染物、不通统计周期，要求不同

				if (type >= 2 && (intCode & 0x0FFF) == 0x0404) {
					// CO
					value = (float) StatUtils.percentile(values, 95);
				} else if (type >= 2 && (intCode & 0x0FFF) == 0x0D71) {
					// O3
					// StatUtils.percentile(values, p)
					// 计算百分位
					// log.debug("计算臭氧90百分位数"+values);
					// StatUtils.p
					value = (float) StatUtils.percentile(values, 90);
				} else if (type == 1 && (intCode & 0x0FFF) == 0x0D71) {
					// 日臭氧8小时
					value = (float) StatUtils.max(values);
				} else {
					// 其他，采用算术平均值
					// mean.evaluate(values);
					value = (float) StatUtils.mean(values);

				}
				high = (float) StatUtils.max(values);
				low = (float) StatUtils.min(values);
				if (radix > 0) {
					value = ((int) (value * radix)) / (float) radix;
					high = ((int) (high * radix)) / (float) radix;
					low = ((int) (low * radix)) / (float) radix;
				}

				icqi = CQIHelper.getCQI(poll.get("pollcode").toString(), value);
				log.debug(String.format("[%s]CQI=%s,VALUE=%s,MAX=%s,Min=%s", pollcode, icqi, value, high, low));
				// sd

				cqi += icqi;
				if (icqi > maxicqi) {
					maxicqi = icqi;
					maxpoll = poll.get("name").toString();
				} else if (icqi == maxicqi) {
					maxpoll = String.format("%s,%s", maxpoll, poll.get("name"));
				}
			} else {
				available = 0;// 当前为不可用
			}

			detail = new HashMap<String, Object>();
			detail.putAll(poll);
			detail.putAll(keys);
			detail.put("icqi", icqi);
			detail.put("high", high);
			detail.put("count", count);
			detail.put("low", low);
			detail.put("value", value);
			this.saveDetail(detail);

		} // end polls
		total = new HashMap<String, Object>();
		total.putAll(keys);
		total.put("cqi", cqi);
		total.put("maxicqi", maxicqi);
		total.put("maxpoll", maxpoll);
		total.put("available", available);
		total.put("count", dayCount);
		log.debug(total.toString());
		this.saveTotal(total);
	}

	/**
	 * 
	 * @param type
	 * @param pollcode
	 *            转换成十六进制值后的污染物代码
	 * @return
	 */
	private int getMinCount(Date datatime, int type, int pollcode) {
		int month;
		switch (type) {
		case 0:// 小时均值
			return 1;
		case 1:// 日均值
			if ((pollcode & 0x0fff) == 0x0D71) {
				return 14;// O3 8小时必须大于14
			}
			return 20;
		case 2:// 周平均
			return 1;
		case 3:// 月平均
			month = DateUtils.toCalendar(datatime).get(Calendar.MONTH);
			return 1;
		/*
		 * if (month == 1) { return 25;// 2月份为25天 } return 27;
		 */
		case 4:// 季度平均
			/*
			 * month = DateUtils.toCalendar(datatime).get(Calendar.MONTH); if
			 * (month < 3) { return 25 + 27 + 27;// 2月份为25天 } else { return 27 *
			 * 3;// 2月份为25天 }
			 */
			return 1;
		case 5:// 半年评价 324
			return 1;
		// return 324;
		case 6:// 年评价 324
			return 1;
		// return 324;

		}
		return 0;
	}

	private double[] getValues(List<Map<String, Object>> result, String fieldName) {
		double[] values = new double[result.size()];
		for (int i = 0; i < values.length; i++) {
			if (result.get(i).get(fieldName) != null) {
				values[i] = Float.parseFloat(result.get(i).get(fieldName).toString());
			}
		}
		return values;
	}

	public void clear(Map<String, Object> args) {
		String sql = String.format(
				"DELETE FROM t_bas_cqi_total_detail WHERE targettype=%s AND targetid='%s' AND type='%s' AND datatime='%s'",
				args.get("targettype"), args.get("targetid"), args.get("type"), args.get("datatime"));
		this.queryService.execute(sql);

		sql = String.format(
				"DELETE FROM t_bas_cqi_total WHERE targettype=%s AND targetid='%s' AND type='%s' AND datatime='%s'",
				args.get("targettype"), args.get("targetid"), args.get("type"), args.get("datatime"));
		this.queryService.execute(sql);

	}

	public void saveTotal(Map<String, Object> args) {
		String sql;
		sql = String.format(
				"INSERT INTO t_bas_cqi_total(cqi,maxicqi,maxpoll,count,available,updatetime,targettype,targetid,type,datatime) VALUES('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",
				args.get("cqi"), args.get("maxicqi"), args.get("maxpoll"), args.get("count"), args.get("available"),
				DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"), args.get("targettype"), args.get("targetid"),
				args.get("type"), args.get("datatime"));
		//log.debug("total:" + sql);
		this.queryService.execute(sql);
	}

	public void saveDetail(Map<String, Object> args) {
		String sql;
		sql = String.format(
				"INSERT INTO t_bas_cqi_total_detail(pollcode,pollname,value,high,low,count,icqi,updatetime,targettype,targetid,type,datatime) VALUES('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",
				args.get("pollcode"), args.get("name"), args.get("value"), args.get("high"), args.get("low"),
				args.get("count"), args.get("icqi"), DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"),
				args.get("targettype"), args.get("targetid"), args.get("type"), args.get("datatime"));
		this.queryService.execute(sql);
	}

	public void destroy() throws Exception {

	}

}
